package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.StudentCourse;

@Repository
public interface StudentCourseDao extends JpaRepository<StudentCourse, Integer>, JpaSpecificationExecutor<StudentCourse> {

	@Query("from StudentCourse where studentId = ?1")
	List<StudentCourse> find(String name);

	@Query("from StudentCourse where studentId like ?1")
	List<StudentCourse> findLike(String name);

	@Query(value = "select * from StudentCourse limit ?, ?", nativeQuery = true)
	List<StudentCourse> findPage(Integer offset, Integer size);

	@Query(value = "select * from StudentCourse where studentId = ? limit ?, ?", nativeQuery = true)
	List<StudentCourse> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from StudentCourse where studentId like ? limit ?, ?", nativeQuery = true)
	List<StudentCourse> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from StudentCourse where studentId = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from StudentCourse where studentId like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from StudentCourse order by id asc")
	List<StudentCourse> findAllAsc();
}

